﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Glorysoft.Auto.Xfw;
using Serilog.Core;
using System;

namespace Glorysoft.EAP.EAPClient.ViewModel
{
    /// <summary>
    /// This class contains properties that a View can data bind to.
    /// <para>
    /// See http://www.galasoft.ch/mvvm
    /// </para>
    /// </summary>
    public class PopupWindowVM : ViewModelBase
    {
        private readonly Logger ServiceLogger = XfwContext.EapLogger;
        /// <summary>
        /// Initializes a new instance of the PopupWindowVM class.
        /// </summary>
        public PopupWindowVM()
        {
        }
        public delegate void CloseWindow();
        public Action CloseParentWindow;
        public CloseWindow CloseWindowEvent;
        private RelayCommand closeCmd;
        public RelayCommand CloseCmd
        {
            get
            {
                return closeCmd ?? (closeCmd = new RelayCommand(Close));
            }
        }
        public virtual void Close()
        {
            try
            {
                if (CloseWindowEvent != null)
                {
                    CloseWindowEvent();
                }
            }
            catch (Exception ex)
            {
                 ServiceLogger.Error(string.Format("{0}: {1}", GetType().Name, ex));
            }
        }
    }
}